package com.ruoyi.leaveManage.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.leaveManage.bo.LeaveManageAddBo;
import com.ruoyi.leaveManage.bo.LeaveManageEditBo;
import com.ruoyi.leaveManage.bo.LeaveManageQueryBo;
import com.ruoyi.leaveManage.service.ILeaveManageService;
import com.ruoyi.leaveManage.vo.LeaveVo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 请假信息Controller
 *
 * @author ruoyi
 * @date 2021-04-26
 */
@Api(value = "请假信息控制器", tags = {"请假信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/leavemanage/manage")
public class LeaveManageController extends BaseController {



    private final ILeaveManageService iLeaveManageService;

    /**
     * 查询请假信息列表
     */
    @ApiOperation("查询请假信息列表")
    @PreAuthorize("@ss.hasPermi('leava:manage:list')")
    @GetMapping("/list")
    public TableDataInfo<LeaveVo> list(LeaveManageQueryBo bo) {
        startPage();
        List<LeaveVo> list = iLeaveManageService.queryList(bo);

        return getDataTable(list);
    }

    /**
     * 导出请假信息列表
     */
    @ApiOperation("导出请假信息列表")
    @PreAuthorize("@ss.hasPermi('leava:manage:export')")
    @Log(title = "请假信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<LeaveVo> export(LeaveManageQueryBo bo) {
        List<LeaveVo> list = iLeaveManageService.queryList(bo);
        ExcelUtil<LeaveVo> util = new ExcelUtil<LeaveVo>(LeaveVo.class);
        return util.exportExcel(list, "请假信息");
    }

    /**
     * 获取请假信息详细信息
     */
    @ApiOperation("获取请假信息详细信息")
    @PreAuthorize("@ss.hasPermi('leava:manage:query')")
    @GetMapping("/{leaveId}")
    public AjaxResult<LeaveVo> getInfo(@PathVariable("leaveId" ) Long leaveId) {
        return AjaxResult.success(iLeaveManageService.queryById(leaveId));
    }

    /**
     * 新增请假信息
     */
    @ApiOperation("新增请假信息")
    @PreAuthorize("@ss.hasPermi('leava:manage:add')")
    @Log(title = "请假信息", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody LeaveManageAddBo bo) {
        return toAjax(iLeaveManageService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改请假信息
     */
    @ApiOperation("修改请假信息")
    @PreAuthorize("@ss.hasPermi('leava:manage:edit')")
    @Log(title = "请假信息", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody LeaveManageEditBo bo) {
        return toAjax(iLeaveManageService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除请假信息
     */
    @ApiOperation("删除请假信息")
    @PreAuthorize("@ss.hasPermi('leava:manage:remove')")
    @Log(title = "请假信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{leaveIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] leaveIds) {
        return toAjax(iLeaveManageService.deleteWithValidByIds(Arrays.asList(leaveIds), true) ? 1 : 0);
    }
}
